<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>申请电子发票</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	
	
	<script language="javascript" type="text/javascript">
	
		//申请电子发票
		function getEinvoice(){
			var polNo=$("#polNo").val();
			var einvoiceName=$("#einvoiceName").val();
			var taxNo=$("#taxNo").val();
			var phoneNo=$("#phoneNo").val();
			var email=$("#email").val();

			if (""==$.trim(polNo)) {
				$.message("error","请输入保单号");
				return;
			}
			if (""==$.trim(einvoiceName)) {
				$.message("error","请输入开票对象名称");
				return;
			}
			if (""==$.trim(phoneNo)&&""==$.trim(email)) {
				$.message("error","手机号邮箱必填其一");
				return;
			}
			$.openLoading();
			$.ajax({
				url : "<%=path%>/einvoice/getEinvoice",
				type : 'POST',
				data:{
					"polNo" : polNo,
					"einvoiceName" : einvoiceName,
					"taxNo" : taxNo,
					"phoneNo" : phoneNo,
					"email" : email
				},
				dataType:'json',
				success:function(data){
					$.closeLoading();
					if (data.result) {
						$.message("success",data.msg);
					}else{
						$.message("false",data.msg);
					}
				}
			});
		}
		
		//查询电子发票
		function queryEinvoice(){
			var polNo=$("#polNo2").val();
			$("#einvoiceNo").empty();
			$("#einvoiceCode").empty();
			$("#einvoiceStatus").empty();
			$("#einvoiceUrl").empty();
			$.openLoading();
			$.ajax({
				url : "<%=path%>/einvoice/queryEinvoice",
				type : 'POST',
				data:{
					"polNo" : polNo
				},
				dataType:'json',
				success:function(data){
					$.closeLoading();
					if (data.result) {
						$('.showEinvoice').css('display','');
						var html = '';
						var einvMap = data.einvMap;
						$("#einvoiceNo").append(einvMap.einvoiceNo);
						$("#einvoiceCode").append(einvMap.code);
						$("#einvoiceStatus").append(einvMap.status);
						$("#einvoiceUrl").append("<a href = '"+einvMap.url+"' target='_blank'>"+einvMap.url+"</a>");
					}else{
						$.message("error",data.errInfo);
					}
				}
			});
		}
		
		//点击查询电子发票 事件
		function EinvoiceInfo(){
			$("#einvoiceInfoDiv").OpenDiv();
		}
		
		//隐藏发票查询信息
		function hideEinvoiceDIV(){
			$('.showEinvoice').css('display','none');
		}
		
		//统一 关闭窗口(传入要关闭DIV的id)
		function closeCurrentDIV(obj){
				$("#"+obj).CloseDiv();	
		}
		
	</script>
</head>
<body >
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
					<td>
						<img src="./images/current_1.jpg">
					</td>
					<td class="current_table_1_td">
						<img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
						<span style=" color:#136bab; ">激活卡管理
							<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>申请电子发票
						</span>
					</td>
					<td><img src="./images/current_3.jpg"></td>
				</tr>
			</tbody>
		</table>
	</div>
		
	
	<div class="current">
		<table border="1" class="table_02" style="height:180px;width: 95%" align="center">
			<tbody>
				<tr>
					<td style="text-align:right;border-right:0px;" width="35%">保单号：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><input type="text" id="polNo" style="width: 200px" class="input_text"><span class="red">*</span>
					</td>
				</tr>
				<tr>
					<td style="text-align:right;border-right:0px;" width="35%">开票对象名称：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><input name="txt3" id="einvoiceName" style="width: 200px"  type="text" class="input_text" value=""><span class="red">*</span>
					</td>
				</tr>
				<tr>
					<td style="text-align:right;border-right:0px;" width="35%">税号：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><input name="txt3" id="taxNo" style="width: 200px"  type="text" class="input_text" value=""><span class="red">开票对象为“企业”时，该字段必填</span>
					</td>
				</tr>
				<tr>
					<td style="text-align:right;border-right:0px;" width="35%">手机号：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><input name="txt3" id="phoneNo" style="width: 200px"  type="text" class="input_text" value=""><span class="red">手机号、邮箱必填其一</span>
					</td>
				</tr>
				<tr>
					<td style="text-align:right;border-right:0px;" width="35%">邮箱：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><input name="txt3" id="email" style="width: 200px"  type="text" class="input_text" value=""><span class="red">手机号、邮箱必填其一</span>
					</td>
				</tr>
			</tbody>
		</table>
		
		<div style="width: 95%;height:30px;" align="center">
		   <input style="font-size: 8px" type="button" value="开具电子发票" onclick="getEinvoice()" class="input_button_2">
		</div>
		<div style="margin-left: 30px" align="left">
		   <input style="background-repeat:no-repeat;background-size:cover;width: 130px" type="button" id="saveMenuBtn" value="电子发票开具查询" onclick="EinvoiceInfo()" class="input_button_2">
		</div>
	</div>
		
		
	<!-- 电子发票开具查询页面 ， 默认隐藏 -->
	<div id="einvoiceInfoDiv" style="width: 65%;  display: none">
		<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('einvoiceInfoDiv');hideEinvoiceDIV()"/></td>
					</tr>
				</table>
		</div>
		<table id= "nlifeEinvoiceInfoDiv" class="table_02" align="center" style="width: 100%;">
			<tbody>
				<tr>
					<td style="text-align:right;border-right:0px;" width="35%">保单号：</td>
					<td style="text-align:left;border-right:0px; margin-right: 0px;" width="65%">
						<input type="text" id="polNo2" class="input_text" style="width: 200px">
						<input type="button" value="查询" onclick="queryEinvoice()" class="input_button_2">
					</td>
				</tr>
				<tr class="showEinvoice" style="display: none">
					<td style="border-right:0px;margin-left:40px" width="35%">电子发票代码：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><span id="einvoiceNo"></span>
					</td>
				</tr>
				<tr class="showEinvoice" style="display: none">
					<td style="border-right:0px;margin-left:40px" width="35%">电子发票号码：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><span id="einvoiceCode"></span>
					</td>
				</tr>
				<tr class="showEinvoice" style="display: none">
					<td style="border-right:0px;margin-left:40px" width="35%">开具状态：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><span id="einvoiceStatus"></span>
					</td>
				</tr>
				<tr class="showEinvoice" style="display: none">
					<td style="border-right:0px;margin-left:40px" width="35%">中信保平台地址：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><span><a href="http://dzdz.ciitc.com.cn" target="_blank">http://dzdz.ciitc.com.cn</a></span>
					</td>
				</tr>
				<tr class="showEinvoice" style="display: none">
					<td style="border-right:0px;margin-left:40px" width="35%">电子发票下载地址：</td>
					<td style="text-align:left;border-right:0px;" width="65%"><span id="einvoiceUrl"></span></br>
					<span class="red">该地址有效期为7天，如逾期未下载需登录中保信平台，根据发票代码、发票号码查询后进行下载</span>
					</td>
				</tr>
			</tbody>
		 </table>
	</div>	
	
	<div id="Loading" style="display:none" align="center">
		<img src="./images/loading.gif" />
	</div>
		
	<!-- 结束 -->
</body>
</html>